<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Rainbow {	 
	
	public function __construct(){
		$CI =& get_instance();
		$CI->load->database();
	}
	
	/* 
		To get next id from table
	*/
	function nextid($tablename,$idfield){
 		$sqlspec="SELECT MAX($idfield) AS latestId FROM $tablename";
		
		$query = $this->db->query("SELECT MAX($idfield) AS latestId FROM $tablename");
		$row = $query->row_array();
		$latestId=$row['latestId'];
 
		$nowId=1;
		if (!empty($latestId)){
			$nowId=$latestId+1;
		}
		return $nowId;
	}
}

/* 
Instant it
	$this->load->library('Rainbow');
	$this->someclass->nextid($tablename,$idfield);
 */
?>